----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 81240 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 240
SPELL.m_sName = "Rend"
SPELL.m_sToolTip =	[[Bleeds the target for
					  up to 50 damage over 5 
					  seconds.]]
SPELL.m_sIcon = "devin/blackbetty/spells/blademaster/minor_wound.png"
SPELL.m_iCoolDown = 5
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_SLOW
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	local range = self.m_iRange
	local totaldamage = 50
	if(target.ArmorStat and target.ArmorStat > 0)then
		totaldamage = totaldamage - target.ArmorStat
	end
	print("Casted "..self.m_sName.."!")
		
	if(target && target:IsValid() && target != pl) then
		pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE2)
		timer.Simple(0.15, function()
			pl:SetNWBool("Casting", false)
			pl:SetNWBool("Casted", false)
			if(pl:GetPos():Distance(target:GetPos()) < range)then
				pl:EmitSound("devin/blackbetty/weapons/swing/special_1.wav", 100, 100+math.random(-10,10))
				ParticleEffectAttach( "slam", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
				pl:EmitSound("devin/blackbetty/weapons/heroic_strike/hit_"..math.random(1,3)..".wav", 100, 100+math.random(-10,10))
				ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 64) + (target:GetAngles():Forward()*24), Angle(0,0,0), target )
				ParticleEffectAttach( "blood_erupt_constant", PATTACH_POINT_FOLLOW, target, target:LookupAttachment("eyes"))
				timer.Simple(5, function() target:StopParticles() end)
				if(timer.Exists("dw_on_"..target:EntIndex()..""))then
					timer.Destroy("dw_on_"..target:EntIndex().."")
				end
				timer.Create("dw_on_"..target:EntIndex().."", 1, 5, function() 
					if(target:Health() <= 0) then 
						timer.Destroy("dw_on_"..target:EntIndex().."")  
						target:StopParticles()
					else
						local dmginfo_im = DamageInfo()
							dmginfo_im:SetDamage(math.ceil(totaldamage / 5)) 
							dmginfo_im:SetDamageType( DMG_SLASH )
							dmginfo_im:SetAttacker( pl ) 
							dmginfo_im:SetDamageForce( Vector( 0, 0, 1000 ) ) 
						target:TakeDamageInfo( dmginfo_im )
						ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 64) + (target:GetAngles():Forward()*24), Angle(0,0,0), target )
					end
				end)
			end
		end)
	end
end




